using GameFramework;
using GameFramework.Event;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityGameFramework.Runtime;

namespace LS.Event
{
    public static class EventExtends
    {
        public static void Subscribe<T>(this EventComponent component, EventHandler<GameEventArgs> handler)
            where T: GameEventArgs, IReference, new()
        {
            component.Subscribe(LSGameEventArgs<T>.EventId, handler);
        }

        public static void Unsubscribe<T>(this EventComponent component, EventHandler<GameEventArgs> handler)
            where T : GameEventArgs, IReference, new()
        {
            component.Unsubscribe(typeof(T).GetHashCode(), handler);
        }

        public static void Fire<T>(this EventComponent component,object sender, Action<T> assembleArg = null)
            where T : GameEventArgs, IReference, new()
        {
            T arg = ReferencePool.Acquire<T>();
            assembleArg?.Invoke(arg);
            component.Fire(sender, arg);
        }

        public static void FireNow<T>(this EventComponent component,object sender, Action<T> assembleArg = null)
            where T : GameEventArgs, IReference, new()
        {
            T arg = ReferencePool.Acquire<T>();
            assembleArg?.Invoke(arg);
            component.FireNow(sender, arg);
        }
    }
}